package com.chijun.mform.full.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.chijun.mform.R;
import com.chijun.mform.create.fragment.FormAddProcessFragment;
import com.chijun.mform.create.mode.FormApprovePerson;
import com.chijun.mform.create.mode.FormApproveProcess;
import com.chijun.mform.full.mode.ModeLoadServerFormConfigData;
import com.example.ccj.b.c.recycler.BaseRecycler;
import com.example.ccj.u.LogUtils;
import com.example.ccj.u.ToastUtils;

import java.util.List;

/**
 * 加载表单审批流程的view
 * @author 驰珺
 * whechat   : chijun9
 * create at : 2024/12/9 22:51
 */
public class ViewLoadFormApprove extends LinearLayout {

    private ModeLoadServerFormConfigData writeFormData;

    public ViewLoadFormApprove(Context context, ModeLoadServerFormConfigData writeFormData) {
        super(context);
        this.writeFormData = writeFormData;
        init();
    }

    public ViewLoadFormApprove(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    BaseRecycler<FormApproveProcess> baseRecycler;

    private void init() {
        setOrientation(LinearLayout.VERTICAL);
        LinearLayout.inflate(getContext(), R.layout.view_load_form_approve,this);
        baseRecycler = findViewById(R.id.view_load_form_approve_rec);
        List<FormApproveProcess> formApproveProcessList = writeFormData.formApproveProcessList;
        baseRecycler.setAdapter(formApproveProcessList,new AdapterLoadFormApproveAdapter(formApproveProcessList,writeFormData.formApprovePersonMap));
    }

    public void setFormData(ModeLoadServerFormConfigData writeFormData){
        this.writeFormData = writeFormData;
        init();
    }

    public boolean check(){
        if (writeFormData.formApproveProcessList != null) {
            for (FormApproveProcess formApproveProcess : writeFormData.formApproveProcessList) {
                if (formApproveProcess.type != FormAddProcessFragment.FA_QI_REN_JIE_DIAN && formApproveProcess.personType != FormAddProcessFragment.APPROVAL_SELECT_MODE_FA_QI_REN_ZI_JI) {
                    List<FormApprovePerson> formApprovePeople = writeFormData.formApprovePersonMap.get(formApproveProcess.id);
                    if (formApprovePeople == null || formApprovePeople.isEmpty()) {
                        ToastUtils.showShort("请选择审批人！");
                        LogUtils.e(formApproveProcess.id +"请选择审批人！");
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
